// pages/reg/reg.js
var app = getApp()
var admin_id = app.globalData.admin_id;

var share = app.globalData.share;
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		disabled:false
	},
	onLoad: function (options) {
		// app.checkUser(app.globalData.openid)
	},
	submit: function (e) {
		console.log(e);
		var that = this;
		if (!(/^1(3|4|5|7|8)\d{9}$/.test(e.detail.value.tell))) {
			wx.showToast({
				title: '电话格式有误',
				image: '../../images/error.png',
				duration: 1000
			})
		}
		else if (e.detail.value.p.length == 0) {
			wx.showToast({
				title: '姓名不为空',
				image: '../../images/error.png',
				duration: 1000
			})
		}
		else {
			that.setData({
				disabled:true
			})
			wx.request({
				url: 'https://xcxu.we-fs.com/index.php/api/goods/reg',
				method: 'post',
				data: {
					admin_id: admin_id,
					mobile: e.detail.value.tell,
					name: e.detail.value.p,
					openid: app.globalData.openid
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded'
				},
				success: function (re) {
					console.log(re)
					if (re.data.code == 0) {
						wx.showToast({
							title: '成功',
							success: function () {
								app.globalData.vip = 1;
								setTimeout(function () {
									wx.switchTab({
										url: '../../pages/index/index',
									})
								}, 2000)
							}
						})
					} else {
						wx.showToast({
							title: '失败',
							success: function () {
								setTimeout(function () {
									wx.switchTab({
										url: '../../pages/index/index',
									})
								}, 2000)
							}
						})
					}
				},
				complete:function(){
					that.setData({
						disabled: true
					})
				}
			})
		}
	},
	toindex:function(){
		wx.switchTab({
			url: '../../pages/index/index',
		})
	}
})